//
//  TableViewCellOfSongRecommend.m
//  UI_homework_22_QQ音乐界面和阿里星球界面
//
//  Created by li cheng on 16/8/13.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "TableViewCellOfSongRecommend.h"
#import "CollectionViewCellOfSongRecommend.h"
@interface TableViewCellOfSongRecommend()<UICollectionViewDelegate, UICollectionViewDataSource>

@end
@implementation TableViewCellOfSongRecommend
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
        [self.contentView addSubview:_collectionView];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[CollectionViewCellOfSongRecommend class] forCellWithReuseIdentifier:@"CollectionViewCellOfSongRecommend"];
    }
    return self;
}
#pragma mark - 布局
- (void)layoutSubviews{
    [super layoutSubviews];
    // contentView 的宽高
    CGFloat widthOfContentView = self.contentView.bounds.size.width;
    CGFloat heightOfContentView = self.contentView.bounds.size.height;
    // collectionView 的宽高
    CGFloat widthOfCollectionView = widthOfContentView;
    CGFloat heightOfCollectionView = heightOfContentView;
    // 控件的 frame 赋值
    _collectionView.frame = CGRectMake(0, 0, widthOfCollectionView, heightOfCollectionView);
    CGFloat egde = 5;
    CGFloat widthOfItem= (widthOfContentView - egde * 4) / 2;
    CGFloat heightOfItem = heightOfCollectionView  - egde * 2;
    _layout.itemSize = CGSizeMake(widthOfItem, heightOfItem);
    _layout.minimumLineSpacing = egde;
    _layout.minimumInteritemSpacing = egde;
    _layout.sectionInset = UIEdgeInsetsMake(egde, egde, egde, egde);
}
#pragma 每个分区的item的数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 2;
}
#pragma cell 赋值
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CollectionViewCellOfSongRecommend *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCellOfSongRecommend" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    return cell;
}
#pragma mark - 其他
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
